package inits

import (
	"fmt"
	"service/basic/config"
	"service/basic/global"

	"github.com/redis/go-redis/v9"
)

func InitRedis() {
	redisConfig := config.Config.Redis
	Addr := fmt.Sprintf("%s:%s", redisConfig.Host, redisConfig.Port)
	global.Rdb = redis.NewClient(&redis.Options{
		Addr:     Addr,
		Password: redisConfig.Password, // no password set
		DB:       redisConfig.Database, // use default DB
	})

	err := global.Rdb.Ping(global.Ctx).Err()
	if err != nil {
		panic(err)
	}
	fmt.Println("redis数据库连接成功")

	// Output: key value
	// key2 does not exist
}
